import request from '@/utils/request'
// 上传接口
export function uploadImage(params: any) {
	return request.post({ url: '/upload/image', params })
}
// 上传附件
export function uploadAttachment(params: any) {
	return request.post({ url: '/upload/attachment', params })
}
//添加附件下载文件名称中文
//李哥修改
/**
 * 通过url下载文件并对下载的文件更名
 * @param {*} url
 * @param {*} filename
 */
 export const downloadFile = (urlAdd: any, filename: any) => {
    function getBlob(urlAdd) {
        return new Promise((resolve) => {
            const XML = new XMLHttpRequest()
            XML.open('GET', urlAdd, true)
            XML.responseType = 'blob'
            XML.onload = () => {
                if (XML.status === 200) {
                    resolve(XML.response)
                }
            }
            XML.send()
        })
    }

    //下载文件
    function saveAs(blob: any, filename: any) {
        const elelink = document.createElement('a')
        elelink.style.display = 'none'
        elelink.download = filename
        elelink.href = window.URL.createObjectURL(blob)
        document.body.appendChild(elelink)
        elelink.click()
        document.body.removeChild(elelink)
    }

    // 调用以上方法进行下载
    getBlob(urlAdd).then((blob) => {
        saveAs(blob, filename)
    })
}